package com.bjc.base.web;

import com.bjc.base.bean.ResultVO;
import com.bjc.base.core.ResultGenerator;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import com.bjc.base.service.IBookBrokenService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import com.bjc.base.bean.request.BookBrokenReqVO;
import com.bjc.base.bean.response.BookBrokenVO;

/**
 * <p>
 * 绘本破损 前端控制器
 * </p>
 *
 * @author 许自辉
 * @since 2018-06-10
 */
@RestController
@RequestMapping("api/book")
@Api(value = "bookBroken-api", tags = { "绘本破损相关接口" })
public class BookBrokenController {

    @Autowired
    private IBookBrokenService bookBrokenService;

	@ApiOperation("分页查询绘本破损")
	@GetMapping("bookBroken/findPage")
	public ResultVO getBookBrokenPage(@RequestParam("pageNum") int pageNum, @RequestParam("pageSize") int pageSize,
			BookBrokenReqVO bookBrokenReqVO) {
		PageHelper.startPage(pageNum, pageSize);
		List<BookBrokenVO> bookBrokenVOs = bookBrokenService.getList(bookBrokenReqVO);
		return ResultGenerator.getSuccess(new PageInfo<BookBrokenVO>(bookBrokenVOs));
	}
	
	@ApiOperation("分页查询绘本破损")
	@GetMapping("bookBroken/find")
	public ResultVO getBookBrokene(BookBrokenReqVO bookBrokenReqVO) {
		BookBrokenVO bookBrokenVO = bookBrokenService.get(bookBrokenReqVO);
		return ResultGenerator.getSuccess(bookBrokenVO);
	}

	@ApiOperation("添加绘本破损")
	@PostMapping("bookBroken/create")
	public ResultVO createBookBroken(@RequestBody BookBrokenReqVO bookBrokenReqVOs) {
		int count = bookBrokenService.insert(bookBrokenReqVOs);
		return ResultGenerator.getInsertSuccess(count);
	}

	@ApiOperation("更新绘本破损")
	@PutMapping("bookBroken/update")
	public ResultVO updateBookBroken(@RequestBody BookBrokenReqVO bookBrokenReqVOs) {
		int count = bookBrokenService.update(bookBrokenReqVOs);
		return ResultGenerator.getUpdateSuccess(count);
	}

	@ApiOperation("批量删除绘本破损")
	@DeleteMapping("bookBroken/deleteList")
	public ResultVO deleteBookBroken(@ApiParam(value = "bookBroken id集合") @RequestBody int[] ids) {
		int count = bookBrokenService.deleteList(ids);
		return ResultGenerator.getDeleteSuccess(count);
	}

}
